#pragma once
#include <stdlib.h>
#include <sys/epoll.h>

class Epoll
{
private:
    static const int gsize = 256;
    int _epfd;

public:
    void CreateEpoll()
    {
        int epfd = epoll_create(gsize);
        if (epfd == -1)
        {
            exit(4);
        }
        _epfd = epfd;
    }
    bool CtrlEpoll(int sock, uint32_t evens)
    {
        epoll_event event;
        event.data.fd = sock;
        event.events = evens;
        return (epoll_ctl(_epfd, EPOLL_CTL_MOD, sock, &event) == 0);
    }
    bool DelSockToEpoll(int sock, uint32_t evens)
    {
        epoll_event event;
        event.data.fd = sock;
        event.events = evens;
        return (epoll_ctl(_epfd, EPOLL_CTL_DEL, sock, &event) == 0);
    }
    bool AddSockToEpoll(int sock, uint32_t evens)
    {
        epoll_event event;
        event.data.fd = sock;
        event.events = evens;
        return (epoll_ctl(_epfd, EPOLL_CTL_ADD, sock, &event) == 0);
    }
    int WaitEpoll(epoll_event *events, int num, int timeout)
    {
        return epoll_wait(_epfd, events, num, timeout);
    }
};